﻿/*
功能：保存cookies函数 
参数：name，cookie名字；value，值
*/
function SetCookie(name,value,Days){
    //var Days = 60;   //cookie 将被保存两个月
    var exp  = new Date();  //获得当前时间
    exp.setTime(exp.getTime() + Days*24*60*60*1000);  //换成毫秒
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
} 
/*
功能：获取cookies函数 
参数：name，cookie名字
*/
function getCookie(name){
    var allcookies = document.cookie;
    var cookie_pos = allcookies.indexOf(name);
    if (cookie_pos != -1){
        cookie_pos += name.length + 1;
        var cookie_end = allcookies.indexOf(";", cookie_pos);
        if (cookie_end == -1){
            cookie_end = allcookies.length;
        }
        var value = unescape(allcookies.substring(cookie_pos, cookie_end));
    }
    return value;
}
/*
功能：删除cookies函数 
参数：name，cookie名字
*/

function delCookie(name){
    var exp = new Date();  //当前时间
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}